<template>
	<view>
		<view class="video-list">
			<view class="video-content" v-for="(item, ind) in meals" :key="ind">
				<!-- <view class="video-cover">
					<image :src="item.picUrl" mode="aspectFill"></image>
				</view> -->
				<view class="video-describe">
					<view style="width: 75%;">
						<view class="video-tit">
							套餐名称:{{item.mealName}}
						</view>
						<view class="video-reader">
							套餐时长:{{item.duration}}小时
						</view>
						<view class="video-reader">
							套餐价格:{{item.price}}元
						</view>
					</view>
					<view>
						<view class="cannel" @click="affirm(item)">
							<text>取消套餐</text>
						</view>
					</view>
				</view>
				<!-- <view class="checkMore" @click="affirm(item)">
					<text>解除绑定</text>
				</view> -->
			</view>
		</view>
		<view class="afrim" @click="addMeal()">绑定套餐</view>
	</view>
</template>
<script>
	import Api from '@/common/api';
	export default {
		components: {

		},
		data() {
			return {
				index: 0,
				meals: [],
				deviceId: null,
				storeId:null
			}
		},
		onLoad(options) {
			this.storeId = options.storeId;
			let deviceId = options.deviceId;
			this.deviceId = deviceId;
			this.getMeals(options.deviceId);
		},
		onShow(options) {
			let that = this;
			// let deviceId = options.deviceId;
			// this.deviceId = deviceId;
			that.getMeals(that.deviceId);
		},
		methods: {
			async getMeals(deviceId) {
				let data = await Api.apiCall('get', Api.qsg.getDeviceMeal, {
					deviceId: deviceId
				});
				if (data) {
					console.log(data)
					this.meals = data
				}
			},
			affirm(item){
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确认解除该套餐与设备的绑定吗?',
					success: function(res) {
						if (res.confirm) {
							that.deleteMeal(item);
						} else if (res.cancel) {
				
						}
					}
				});
			},
			async deleteMeal(item) {
				console.log(JSON.stringify(item))
				let deviceId = this.deviceId;
				let mealId = item.id;
				let params = {
					id: deviceId,
					mealId: mealId
				}
				let data = await Api.apiCall('post', Api.qsg.deleteBind,params);
				if (data) {
					this.getMeals(this.deviceId)
				}
			},
			addMeal() {
				uni.navigateTo({
					url: '/pages/meal/devicemeal?storeId=' + this.storeId + '&deviceId=' + this.deviceId
				})
			}
		}
	}
</script>

<style>
	.cannel{
		width: 130rpx;
		height: 40rpx;
		background: #0DA944;
		border-radius: 10rpx;
		font-size: 24rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 40rpx;
		text-align: center;
		margin-top: 60rpx;
	}
	.afrim{
		width: 650rpx;
		height: 80rpx;
		background: #0DA944;
		border-radius: 30rpx;
		font-size: 28rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 80rpx;
		text-align: center;
		position: fixed;
		bottom: calc(100% - 95%);
		margin-left: 40rpx;
	}
	.priceSign{
		font-size: 24rpx;
	}
	.priceNum{
		font-size: 32rpx;
		font-weight: bold;
	}
	.priceIcon{
		font-size: 24rpx;
	}
	.schoolName{
		width: 750rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		font-size: 50rpx;
		font-weight: bold;
		color: #000000;
	}
	.uni-input{
		padding: 0 24rpx;
	}
	.choese{
		width: 750rpx;
		display: flex;
		box-sizing: border-box;
		padding:0 30rpx;
		color: #888888;
	}
	.dataName{
		height: 60rpx;
	}
	.currentSchool{
		height: 60rpx;
		background: #FFFFFF;
	}
	.video-tit {
		font-size: 30rpx;
		color: #62b074;
		font-weight: bold;
		display: inline-block;
		vertical-align: top;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}
	
	.checkMore text{
		display: block;
		width: 100%;
		height: 60rpx;
		line-height: 58rpx;
		font-size: 24rpx;
		color: #172a89;
		border: 1px solid #172A89;
		text-align: center;
		box-sizing: border-box;
		margin-top: 46rpx;
		border-radius: 50rpx;
	}
	
	.checkMore {
		font-size: 24rpx;
		color: #172a89;
		flex: 1;
	}
	
	.video-price {
		font-size: 30rpx;
		color: #666;
		overflow: hidden;
		display: inline-block;
		vertical-align: top;
		text-align: center;
		box-sizing: border-box;
	}
	
	.video-reader {
		font-size: 24rpx;
		color: #666;
	}
	
	.video-describe {
		display: inline-block;
		vertical-align: top;
		display: flex;
		width: 100%;
		padding-left: 20rpx;
	}
	
	.video-cover {
		width: 100rpx;
		height: 100rpx;
		margin: 30rpx 30rpx 30rpx 0;
		display: inline-block;
		vertical-align: top;
		border-radius: 50%;
		flex: 1;
	}
	
	.video-cover image {
		width: 100rpx;
		height: 100rpx;
		background: #FFFFFF;
		border-radius: 50%;
	}
	
	.video-content {
		width: 690rpx;
		padding: 22rpx 0;
		border: 1rpx solid #f1f1f1;
		box-shadow: 0 0 10px #e6e6e6;
		border-radius: 20rpx;
		box-sizing: border-box;
		display: flex;
		margin-top: 20rpx;
	}
	
	.video-content:last-child {
		border: none;
	}
	
	.video-list {
		width: 750rpx;
		height: auto;
		padding: 0 30rpx;
		box-sizing: border-box;
	}
</style>
